<?php

/**
 * Haefko - your php5 framework
 *
 * @author      Jan Skrasek
 * @copyright   Copyright (c) 2007 - 2009, Jan Skrasek
 * @link        http://haefko.programujte.com
 * @license     http://www.opensource.org/licenses/mit-license.html
 * @version     0.8 - $Id: debug.exception.phtml 65 2008-12-28 21:41:24Z skrasek.jan $
 * @package     Haefko_Libs
 */


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="robots" content="noindex,noarchive" />
	<meta name="generator" content="Háefko - your php5 framework" />
	<title>Exception: <?= htmlspecialchars($exception->getMessage()) ?></title>

	<style type="text/css" media="screen">
	body {
		background: white;
		font-family: Calibri, sans-serif;
		margin: 0;
		padding: 0;
	}
	#header {
		background: white;
		border-top: 10px solid #d70000;
		font-family: Candara, 'Trebuchet MS', 'Geneva CE', lucida, sans-serif;
		padding: 20px 25px;
	}
	#header h1 {
		color: #444;
		margin: 0;
		padding: 0;
	}
	#header p {
		margin: 0;
		color: #aa0000;
		font-size: 18px;
	}
	.block {
		background: #f3f3f3;
		border: 1px solid #dedede;
		margin: 10px 25px;
	}
	.block p {
		border-bottom: 1px solid #dedede;
		padding: 4px 10px;
		margin: 0;
	}
	code {
		font-family: Consolas, 'Lucida Console', 'Monaco CE', fixed, monospace;
		font-size: 14px;
	}
	pre {
		background: #fff8d2;
		padding: 2px;
		margin: 0;
		overflow: auto;
	}
	.line-num {
		color: black;
		margin: 0 8px 0 4px;
	}
	#line {
		background: #edce20;
		color: #3a3a3a;
		display: block;
		width: 100%;
	}
	table td {
		text-align: right;
	}
	table th {
		text-align: left;
	}
	</style>
</head>
<body>
<div id="header">
	<h1>Exception</h1>
	<p><?= htmlspecialchars($exception->getMessage()); ?></p>
</div>

<div class="block">
<?php
	$i = 0;
	$trace = $exception->getTrace();
	foreach ($trace as $i => $item) {
		if (isset($item['file']) && strpos($item['file'], Application::get()->corePath) === false)
			break;
	}

	if (empty($trace[$i]))
		$i = 0;

	$file = trim(file_get_contents($trace[$i]['file']));
	$file = preg_replace("#\r(?!\n)|(?<!\r)\n#", "\r\n", $file);
	$file = highlight_string($file, true);
	$file = explode("<br />", str_replace("\n", '', $file));

	$line = $trace[$i]['line'];
	$lines = strlen((string) count($file));

	foreach ($file as $l => & $row) {
		$rl = '<span class="line-num">' . str_pad($l + 1, $lines, ' ', STR_PAD_LEFT) . '</span>';

		if ($line == $l + 1) {
			preg_match('#.*(<span[^>]+>)#', $row, $m);
			$row = '<span id="line">' . $rl . strip_tags($row) . '</span>' . $m[1];
		} else {
			$row = $rl . $row;
		}
	}

	$file = implode("", $file) . '</code>';
?>
	<p><strong>File: </strong><?= Tools::relativePath($trace[$i]['file']) ?>&nbsp;&nbsp;
	<strong>Line: </strong><a href="#line"><?= $line ?></a></p>
	<pre><?= $file ?></pre>
</div>

<div class="block">
	<p>Rendered contents:</p>
	<pre><?= htmlspecialchars($rendered) ?></pre>
</div>

<div class="block" style="font-size: 12px">
<table>
<tr>
	<td>rendering time:</td>
	<th><?= self::getTime() ?>ms</th>
</tr>
<tr>
	<td>server:</td>
	<th><?= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] ?></th>
</tr>
<tr>
	<td>generated at:</td>
	<th><?= date('d.m.Y, h.i') ?></th>
</tr>
<tr>
	<td></td>
	<th><a href="http://haefko.programujte.com">háefko</a> 0.8</th>
</tr>
</table>
</div>
</body>
</html>